import 'package:flutter/material.dart';

class SampleInheritedWidget extends StatefulWidget {
  const SampleInheritedWidget({Key? key}) : super(key: key);

  @override
  _SampleInheritedWidgetState createState() => _SampleInheritedWidgetState();
}

class _SampleInheritedWidgetState extends State<SampleInheritedWidget> {
  int count = 0;

  void _incrementCount() {
    setState(() {
      count++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("StatefulWidget示例"),
      ),
      body: CounterWiget(count, _incrementCount),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCount,
        child: Icon(Icons.add),
      ),
    );
  }
}

class CounterWiget extends StatelessWidget {
  final int count;

  final VoidCallback incrementCont;

  CounterWiget(this.count, this.incrementCont, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: ActionChip(
        label: Text("$count"),
        onPressed: incrementCont,
      ),
    );
  }
}
